package demo.java.lang;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class RunnableDemo implements Runnable {

    private static Logger logger = LoggerFactory.getLogger(RunnableDemo.class);

    private String name;
    private long cost;

    @Override
    public String toString() {
        return "RunnableDemo [name=" + name + ", cost=" + cost + "]";
    }

    public RunnableDemo(String name, int expectedCostMs) {
        this.name = name;
        this.cost = expectedCostMs;
    }

    @Override
    public void run() {
        logger.info("task " + name + " is running ");
        if (cost > 0) {
            ThreadDemo.safeSleep(cost);
        }
        logger.info("task " + name + " is over");
    }
}
